package gdca.webservice.common;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class GdcaServlet extends javax.servlet.http.HttpServlet {
	private static final String CONTENT_TYPE = "text/html; charset=GBK";

	public void destroy() {
	}

	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		performTask(req, resp);
	}

	public void init(ServletConfig config) throws ServletException {
		super.init(config);
	}

	public void performTask(HttpServletRequest req, HttpServletResponse res) {
		String busyType = req.getParameter("busyType");
		String trustId = req.getParameter("trustId");
		String cn = req.getParameter("cn");
		String o = req.getParameter("o");
		String ou = req.getParameter("ou");
		String c = req.getParameter("c");
		String s = req.getParameter("s");
		String l = req.getParameter("l");
		String e = req.getParameter("e");
		String nsrdjh = req.getParameter("nsrdjh");
		String zsh = req.getParameter("zsh");
		String userPassword = req.getParameter("userPassword");
		String initPassword = req.getParameter("initPassword");
		String publicKey = req.getParameter("publicKey");
		GdcaOperate gdcaOperate = new GdcaOperate();
		RequestInfo requestInfo = new RequestInfo();
		requestInfo.setBusyType(busyType);
		requestInfo.setC(c);
		requestInfo.setCn(cn);
		requestInfo.setE(e);
		requestInfo.setPassword(userPassword);
		requestInfo.setInitPassword(initPassword);
		requestInfo.setL(l);
		requestInfo.setNsrdjh(nsrdjh);
		requestInfo.setO(o);
		requestInfo.setOu(ou);
		requestInfo.setS(s);
		requestInfo.setTrustId(trustId);
		requestInfo.setZsh(zsh);
		requestInfo.setPublicKey(publicKey);

		String success = "jsp/writekey.jsp";
		RequestDispatcher rd = req.getRequestDispatcher(success);
		try {
			ResponseInfo responseInfo = gdcaOperate.dealGdcaServise(requestInfo);
			req.setAttribute("responseInfo", responseInfo);
			String i_isBack = "Y";
			if (busyType.equals("001") || busyType.equals("005"))//新增或补发
			{
				i_isBack = "N";
			}
			req.setAttribute("i_isBack", i_isBack);
			req.setAttribute("busyType", busyType);
			rd.forward(req, res);
		} catch (Exception e1) {
			try {
				rd.forward(req, res);
			} catch (Exception e2) {
			}
		} finally {

		}

	}
}
